import fetch from 'node-fetch';
import { Swagger } from '../interface';

export async function remoteJson(originUrl: string, options = {}): Promise<Swagger> {
  try {
    const response = await fetch(originUrl, options);
    if (response.status === 200) {
      const swagger = await response.text();
      return JSON.parse(swagger);
    }
  } catch (e) {
    throw new Error(e.message);
  }
};